package PAPModified;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLOntology;

public class Block {
	/** Coupling is a map of hashmap of other block and value of coupling. */
	private Map<Block, Double> coupling = new HashMap<Block, Double>();
	/** value of internal sum of links (cohesiveness). */
	private Double cohesiveness;
	/** The list of class in this block. */
	private ArrayList<OWLClass> listOfClasses = new ArrayList<OWLClass>();
	private OWLOntology ontology;
	
	public Block(OWLOntology ontology) {
		super();
		this.ontology = ontology;
	}

	public void addClass(OWLClass owlClass){
		listOfClasses.add(owlClass);
	}
	
	public void addAllClasses(ArrayList<OWLClass> owlClasses){
		listOfClasses.addAll(owlClasses);
	}
	
	public void removeClass(OWLClass owlClass){
		listOfClasses.remove(owlClass);
	}
	
	public void putCoupling(Block key, Double value){
		if (coupling.containsKey(key)) {
			coupling.replace(key, value);
		} else {
			coupling.put(key, value);
		}
	}
	
	public void removeCoupling(Long key, Double value){
		coupling.remove(key);
	}
	
	/** calculate the number of classes in this block. */
	public double sizeOfBlock(){
		return Double.valueOf(listOfClasses.size());
	}
	
	/** return the block with best coupling for this block */
	public Block maxCoupling(){
		Block best = null;
		for (Block blk : coupling.keySet()) {
			if (best == null) {
				best = blk;
			} else {
				if (coupling.get(blk) > coupling.get(best)) {
					best = blk;
				}
			}
		}
		return best;
	}
	
	public Map<Block, Double> getCoupling() {
		return coupling;
	}
	public void setCoupling(Map<Block, Double> coupling) {
		this.coupling = coupling;
	}
	public Double getCohesiveness() {
		return cohesiveness;
	}
	public void setCohesiveness(Double cohesiveness) {
		this.cohesiveness = cohesiveness;
	}
	public ArrayList<OWLClass> getListOfClasses() {
		return listOfClasses;
	}
	public void setListOfClasses(ArrayList<OWLClass> listOfClasses) {
		this.listOfClasses = listOfClasses;
	}

	public OWLOntology getOntology() {
		return ontology;
	}

	public void setOntology(OWLOntology ontology) {
		this.ontology = ontology;
	}

}
